#include "i2c.h"
#include "esp_log.h"
#include "driver/i2c.h"
#include "driver/i2c_master.h"
#include "../hal_config.h"

const char* HAL_I2C_TAG = "I2C";

void hal_i2c_init(void) {
    ESP_LOGI(HAL_I2C_TAG, "Initializing I2C bus...");

    // 创建 I2C 总线配置
    const i2c_master_bus_config_t bus_config = {
        .i2c_port = PIN_I2C_PROT,
        .sda_io_num = PIN_I2C_SDA,
        .scl_io_num = PIN_I2C_SCL,
        .clk_source = I2C_CLK_SRC_DEFAULT,
        .glitch_ignore_cnt = 0,
        .flags = {
            .enable_internal_pullup = true,
        },
    };

    // 创建 I2C 总线句柄
    i2c_master_bus_handle_t i2c_bus_handle = NULL;
    ESP_ERROR_CHECK(i2c_new_master_bus(&bus_config, &i2c_bus_handle));


    ESP_LOGI(HAL_I2C_TAG, "I2C master bus initialized.");
}
